package cn.shyouchi.wuguanjia.android.ui.attendance.report;

import android.view.View;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;

import java.util.List;

import cn.shyouchi.wuguanjia.android.R;
import cn.shyouchi.wuguanjia.android.utils.ToastUtil;

/**
 * Created by Eenie on 2016/11/29 at 16:09
 * Email: 472279981@qq.com
 * Des:
 */

public class StaffReportAdapter extends BaseQuickAdapter<StaffReportEntity.ResultMessageBean.PlanBean, BaseViewHolder> {


    private int position = 0;
    StaffReportContract.View mView;


    public StaffReportAdapter(List<StaffReportEntity.ResultMessageBean.PlanBean> data, StaffReportContract.View view) {

        super(R.layout.item_attendance_report_layout, data);
        this.mView = view;
    }

    @Override
    protected void convert(BaseViewHolder holder, final StaffReportEntity.ResultMessageBean.PlanBean entity) {

//statusCode:  0:可以报岗      1：时间过了      2：时间没到  3：报过了


        if (entity.getStatusCode() == 0) {
            holder.setBackgroundRes(R.id.tv_position, R.drawable.shape_circle_gray);
            holder.setText(R.id.tv_report_complete_time, "");
        } else if (entity.getStatusCode() == 1) {
            holder.setBackgroundRes(R.id.tv_position, R.drawable.shape_circle_red);
            holder.setText(R.id.tv_report_complete_time, "报岗时间已过");
        } else if (entity.getStatusCode() == 3) {
            holder.setBackgroundRes(R.id.tv_position, R.drawable.shape_circle_blue);
            holder.setText(R.id.tv_report_complete_time, String.format("完成时间：%1s", entity.getActual().getCompletetime()));
        } else {
            holder.setBackgroundRes(R.id.tv_position, R.drawable.shape_circle_gray);
            holder.setText(R.id.tv_report_complete_time, "");
        }

        holder.setText(R.id.tv_report_post, String.format("岗位：%1s", mView.fetchData().getPostsetting().getPostsetting_name()));
        holder.setText(R.id.tv_report_time, String.format("报岗时间：%1s", entity.getTime()));


//        if (holder.getAdapterPosition() == 0) {
//            holder.setBackgroundRes(R.id.tv_position, R.drawable.shape_circle_blue);
//        } else if (holder.getAdapterPosition() == 1) {
//            holder.setBackgroundRes(R.id.tv_position, R.drawable.shape_circle_red);
//        } else {
//            holder.setBackgroundRes(R.id.tv_position, R.drawable.shape_circle_gray);
//        }


        holder.setText(R.id.tv_position, String.valueOf(holder.getAdapterPosition() + 1));

        holder.getView(R.id.tv_check_detail).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                mView.onCheckInfoClick(entity);
            }
        });

        holder.getView(R.id.img_take_photo).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                switch (entity.getStatusCode()) {
                    case 0:
                        mView.onTakePhotoClick(entity);
                        break;
                    case 1:
                        ToastUtil.showToast("报岗时间已过");
                        break;
                    case 2:
                        ToastUtil.showToast("报岗时间没到");
                        break;
                    case 3:
                        ToastUtil.showToast("该报岗时间已经报过");
                        break;
                }

            }
        });
    }

    public void resfreshStatu() {
        notifyDataSetChanged();
    }


}
